Title Banner


Technical Q&A's


HW 01 - Determining If a PCI Bus Exists (Updated 27-Nov-96)


Q How do I determine if the PowerMacintosh has PCI expansion slots?

A The only way to do this is to use the Name Registry. Use the RegistryEntrySearch routine to search for entries whose "device_type" value is "pci". If an entry is found (RegistryEntrySearch returns noErr and done is false), there is at least one PCI bus. The Name Registry is documented in Chapter 8 of "Designing PCI Cards and Drivers for Power Macintosh Computers".

To allow your program to run on machines that don't have the Name Registry, you should weak link to "NameRegistryLib". You can then determine whether the Name Registry is available by testing the address of a symbol in the library against kUnresolvedCFragSymbolAddress. This technique is documented in Inside Macintosh: PowerPC System Software, p1-25.

The following snippet demonstrates both techniques:

static Boolean HasPCISlots(void)
    // Returns true if the machine has any PCI slots.   Guards against the
    //  absence of NameRegistryLib, so you can run this function on any PPC
    //  computer.
{
    Boolean result;
    RegEntryIter myIterator;
    OSStatus err;
    Boolean done;
    RegEntryID foundEntry;

    // Assume the worst.
    result = false;

    // Check that the link to NameRegistryLib was successfull.
    if (RegistryEntryIterateCreate != kUnresolvedCFragSymbolAddress) {

        // Create an iterator
        if (RegistryEntryIterateCreate(&myIterator) == noErr) {

            // Search for a node of type "pci".
            (void) RegistryEntryIDInit(&foundEntry);
            err = RegistryEntrySearch(&myIterator, kRegIterContinue,
                                        &foundEntry, &done,
                                        "device_type",
                                        "pci", sizeof("pci"));

            // See whether we found one.
            if (err == noErr && !done) {
                result = true;
                (void) RegistryEntryIDDispose(&foundEntry);
            }

            (void) RegistryEntryIterateDispose(&myIterator);
        }
    }

    return (result);
}


--Quinn "The Eskimo!"
devsupport@apple.com

Technical Support
Technical Q&As
Contents | Next Question

Navigation graphic, see text links

Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help